﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spring.Objects.Factory.Config;

namespace Strongshell.Recoil.Core.Composition.Parsing.DependencyInjection
{
    public abstract class NestingDependencyInjectorBase : DependencyInjectorBase
    {
        private readonly IObjectConfigurationRegistry objectConfigurationRegistry;

        protected NestingDependencyInjectorBase(IObjectConfigurationRegistry objectConfigurationRegistry, ObjectConfiguration currentConfiguration, Type expectedType) 
            : base(currentConfiguration, expectedType)
        {
            this.objectConfigurationRegistry = objectConfigurationRegistry;
        }

        public override ObjectConfiguration SelectNestableObjectConfiguration(Type type)
        {
            var newObjectConfiguration = objectConfigurationRegistry.RegisterUnique(type);

            Inject(new RuntimeObjectReference(newObjectConfiguration.Name));

            return newObjectConfiguration;
        }
    }
}
